package com.chinanet.netelementmodel;
import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;
/**
 * HP_WebService_Imp_findErrorcode
 * 错误代码查询
 * @author xuzhi
 *
 */
public class HP_WebService_Imp_findErrorcode implements WorkInterFace {

	@Override
	public String getName() {
		return "HP错误代码查询";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[1];
		in[0]=new Attr("Login", "值表示登录名全称：如hzhza12345678;对于普通宽带用户,不需要带后缀@zj(默认为@zj),但是对于卡用户,必须带后缀@tyt", AttrType.TYPE_String, true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[13];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("Result", "返回结果的根节点", AttrType.TYPE_String, true);
		out[2]=new Attr("errorcodes", "表示一组错误代码,如果有详单记录, 那么errorcodes节点将包含errorcode子节点", AttrType.TYPE_String, true);
		out[3]=new Attr("errorcode", "表示一条错误代码", AttrType.TYPE_String, true);
		out[4]=new Attr("login", "值表示完整的用户登录名", AttrType.TYPE_String, true);
		out[5]=new Attr("auth_time", "拨号时间", AttrType.TYPE_String, true);
		out[6]=new Attr("auth_result", "错误原因", AttrType.TYPE_String, true);
		out[7]=new Attr("remark", "详细信息", AttrType.TYPE_String, true);
		out[8]=new Attr("nas_ip", "NAS_IP", AttrType.TYPE_String, true);
		out[9]=new Attr("nas_port_type", "NAS端口类型:6:小灵通接入;15:	ATM接入;16:LAN接入;19:WLAN省内接入;20001:WLAN省外漫游;30000:漫游来访清单", AttrType.TYPE_String, true);
		out[10]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[11]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		out[12]=new Attr("resultisnull", "0：非空；1：空", AttrType.TYPE_Int, true);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		WebService webService=new WebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setClientSysName("CDMA");
		attrsIn.setFunctionName("gethperror");
		attrsIn.setRequestMessage("<DN>"+(String) data.get("Login")+"</DN>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn);
		String flag=webService.getPattern("flag", returnXml);
		if(flag.equals("true")){
			map.put("ReturnCode", 0);
			map.put("Result", webService.getPattern("Result", returnXml));
			if(webService.getPattern("Result", returnXml).equals("<errorcodes/>")){
				map.put("resultisnull", 1);
			}else{
				map.put("resultisnull", 0);
			}
			map.put("errorcode", webService.getPattern("errorcode", returnXml));
			map.put("login", webService.getPattern("login",webService.getPattern("errorcode", returnXml)));
			map.put("auth_time", webService.getPattern("auth_time",webService.getPattern("errorcode", returnXml)));
			map.put("auth_result", webService.getPattern("auth_result",webService.getPattern("errorcode", returnXml)));
			map.put("remark", webService.getPattern("remark",webService.getPattern("errorcode", returnXml)));
			map.put("nas_ip", webService.getPattern("nas_ip",webService.getPattern("errorcode", returnXml)));
			map.put("nas_port_type", webService.getPattern("nas_port_type",webService.getPattern("errorcode", returnXml)));
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", 1);
			map.put("Result", "");
			map.put("errorcode", "");
			map.put("login", "");
			map.put("auth_time", "");
			map.put("auth_result","");
			map.put("remark","");
			map.put("nas_ip","");
			map.put("nas_port_type","");
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
